from tkinter import *
from tkinter import filedialog


def OpenFile():
    PathText.config(state=NORMAL)
    global IsFileOpen
    filename = filedialog.askopenfilename(filetypes = [("binary file","*.bin")])
    print(filename)
    if filename == "":
        IsFileOpen = False
    else:
        IsFileOpen = True
    print(IsFileOpen)
    PathText.delete(1.0,END)
    PathText.insert("insert",filename)
    PathText.config(state=DISABLED)

def Update():
    global IsFileOpen
    VersionTextStr = VersionText.get()
    print("version is ",VersionTextStr)
    if(VersionTextStr == ""):
        print("version is none")
    if(IsFileOpen == True and VersionTextStr != ""):
        SuccessMSG.set("成功!")
        print("升级成功！")
    else:
        SuccessMSG.set("失败!")
        print("升级失败！")
'''
def Update():
    global IsFileOpen
    VersionTextStr = VersionText.get("0.0",END).split("\n")
    print("version is ",VersionTextStr)
    if(VersionTextStr[0] == ""):
        print("version is none")
    if(IsFileOpen == True and VersionTextStr[0] != ""):
        SuccessMSG.set("成功!")
        print("升级成功！")
    else:
        SuccessMSG.set("失败!")
        print("升级失败！")
'''
window = Tk()
Tk.title(window,"升级工具")
Tk.geometry(window,"500x200")
Label(window,text = "文件路径:",font = ("KaiTi_GB2312",12)).grid(row = 0,column = 1,sticky = W)
PathText = Text(window,width = 60,height = 2)
PathText.grid(row = 0,column = 2,columnspan = 3)
Button(window,text = "打开文件",font = ("KaiTi_GB2312",12),command = OpenFile).grid(row = 1,column = 1,columnspan = 4,pady = 10)
Label(window,text = "软件版本:",font = ("KaiTi_GB2312",12)).grid(row = 2,column = 1,pady = 15,sticky = W)
VersionText = Entry(window,width = 16,font = ("KaiTi_GB2312",12))
#VersionText = Text(window,width = 16,height = 1,font = ("KaiTi_GB2312",12))
VersionText.grid(row = 2,column = 2,sticky = W)
SuccessMSG = Variable()
IsFileOpen = False
Label(window,text = "升级结果:",font = ("KaiTi_GB2312",12)).grid(row = 2,column = 3)
Label(window,textvariable = SuccessMSG,font = ("KaiTi_GB2312",12)).grid(row = 2,column = 4)
Button(window,text = "开始升级",font = ("KaiTi_GB2312",12),command = Update).grid(row = 3,column = 1,columnspan = 4)
mainloop()
